<?php

namespace App\Http\Requests\Api\V1\Auth;

use App\Models\Customer\Customer;
use Dingo\Api\Http\FormRequest;

class AuthRequest extends FormRequest
{

    protected function prepareForValidation()
    {
        $auth_type = request()->input('auth_type', Customer::AUTH_WE_CHAT);
        $this->request->set('auth_type', $auth_type);
    }

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'auth_type'      => [
                'required'
            ],
            'code'           => [
                'required_if:auth_type,' . Customer::AUTH_WE_CHAT
            ],
            'tel'            => [
                'required_if:auth_type,' . Customer::AUTH_TEL,
                'numeric',
                'min:11'
            ],
            'password'       => [
                'required_if:auth_type,' . Customer::AUTH_TEL
            ],
            'user_info'      => [
                'nullable',
                'array'
            ],
            'getUserInfo'    => [
                'nullable'
            ]
        ];
    }
}
